package br.serpro.curso.projeto.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper {
	public static final String BANCO = "whishlist";
	public static final String ITEM_TABELA = "item";
	public static SQLiteDatabase db;
	
	public DBOpenHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		db = this.getReadableDatabase();
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		final StringBuilder sql = new StringBuilder();
		sql.append("CREATE TABLE item (");
		sql.append("_id INTEGER PRIMARY KEY AUTOINCREMENT,");
		sql.append("nome TEXT,");
		sql.append("local TEXT,");
		sql.append("categoria TEXT,");
		sql.append("contato TEXT,");
		sql.append("preco_minimo TEXT,");
		sql.append("preco_maximo TEXT,");
		sql.append("notificar INTEGER");
		sql.append(")");
		database.execSQL(sql.toString());		
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
	}
	
	public static Cursor queryCategorias(){
		return db.query(DBOpenHelper.ITEM_TABELA, new String[]{"categoria"}, null, null, "categoria", null, "categoria");
	}
}